<?php

namespace app\common\model\xiluhouse;

use think\Model;

class MoneyLog extends Model
{

    // 表名
    protected $name = 'xiluhouse_money_log';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    const TYPE_USER = 1;
    const TYPE_LESSOR = 2;
    const TYPE_BROKER = 3;

    const MONEY_TYPE_USER_BUY           = 1; //上级贡献
    const MONEY_TYPE_LESSOR_RENTER      = 2; //房东租金
    const MONEY_TYPE_BROKER_COMMISSION  = 3; //经纪人佣金
    const MONEY_TYPE_USER_WITHDRAW      = 4; //用户提现
    const MONEY_TYPE_LESSOR_WITHDRAW    = 5; //房东提现
    const MONEY_TYPE_BROKER_WITHDRAW    = 6; //经纪人提现
    const MONEY_TYPE_USER_WITHDRAW_REFUSE= 7; //用户提现拒绝
    const MONEY_TYPE_LESSOR_WITHDRAW_REFUSE= 8; //房东提现拒绝
    const MONEY_TYPE_BROKER_WITHDRAW_REFUSE= 9; //经纪人提现拒绝
    const MONEY_TYPE_LESSOR_PLATFORM = 10; // 平台服务费


    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'createtime_text',
    ];

    public function getCreatetimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['createtime']) ? $data['createtime'] : '');
        return time_tran($value);
    }

    public function user()
    {
        return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
